<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #toolbar>
        <a-button type="primary" @click="handlerUseCheck(selectedRow)" :disabled="!hasSelectedRows || selectedRow.useState == 2" v-auth="'ACTION_singleUseCheck'"> 核验使用 </a-button>
      </template>
    </BasicTable>
    <SingleUseCheckDrawer @register="registerSingleUseCheckDrawer" @success="reload" />
  </div>
</template>
<script lang="ts" setup name="singleUserGoods">
import { BasicTable } from '@apps/antd-admin/src/components/Table';
import { useDrawer } from '@apps/antd-admin/src/components/drawer';
import SingleUseCheckDrawer from './components/SingleUseCheckDrawer.vue';
import { columns, searchFormSchema } from './data/data';
import { useMessage } from '@apps/antd-admin/src/hooks/web/useMessage';
import { useBaseTable } from '@apps/antd-admin/src/hooks';
import { Api } from './data/api';

const { createMessage } = useMessage();
const [registerSingleUseCheckDrawer, { openDrawer: openSingleUseCheckDrawer }] = useDrawer();
const { prefixCls, tableContext, handleDelete, handleSuccess, handlePost, handleBatchDelete } = useBaseTable({
  designScope: 'singleUserGoods-template',
  tableProps: {
    //表格标题
    title: '单次服务列表',
    //主键字段
    rowKey: 'userGoodsId',
    //列表查询handler
    handlerName: 'appSingleUserGoodsListHandler',
    //列表接口
    listUrl: Api.page,
    //列定义
    columns,
    //查询表单配置
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
      showExportButton: true,
    },
    showActionColumn: false,
    clickToRowSelect: true,
    rowSelection: {
      type: 'radio',
    },
  },
});
const [registerTable, { reload }, { rowSelection, selectedRow, hasSelectedRows }] = tableContext;

function handlerUseCheck(record: Recordable) {
  openSingleUseCheckDrawer(true, {
    record,
    isUpdate: true,
  });
}
</script>
